package testcase.doctor;

import static org.testng.Assert.assertEquals;
import org.json.JSONArray;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import api.doctor.FavouriteTemplate;
import common.Host;
import common.TestData;

/**
 * 帮忙医APP我的收藏模板清淡FavouriteTemplate测试用例
 * @author lipeng
 *
 */
public class TestFavouriteTemplate {
	/**
	 * 帮忙医APP我的收藏模板清单FavouriteTemplate测试环境数据驱动
	 * @return 测试数据
	 * @throws Exception
	 */
      @DataProvider (name = "Test_Get")
      public static String[][] testFavouriteTemplate_Get() throws Exception{
    	  Host.setup("Test");
    	  TestData td = new TestData("doctor/TestFavouriteTemplate.xml");
    	  return td.getParam("Get");
      }
      
      
      /**
  	 * 帮忙医APP添加收藏模板FavouriteTemplate测试环境数据驱动
  	 * @return 测试数据
  	 * @throws Exception
  	 */
        @DataProvider (name = "Test_Post")
        public static String[][] testFavouriteTemplate_Post() throws Exception{
      	  Host.setup("Test");
      	  TestData td = new TestData("doctor/TestFavouriteTemplate.xml");
      	  return td.getParam("Post");
        }
        
        /**
         * 帮忙医App删除收藏模板FavouriteTemplate测试用例环境数据驱动
         * @return
         * @throws Exception
         */
        @DataProvider(name = "Test_Del")
        public static String[][] TestFavouriteTemplate_Del() throws Exception{
        	Host.setup("Test");
        	TestData td = new TestData("doctor/TestFavouriteTemplate.xml");
        	return td.getParam("Del");
        }
        
      /**
       * 帮忙医APP我的收藏模板清单FavouriteTemplate测试环境用例
       * @param token
       * @throws Exception
       */
      @Test(dataProvider="Test_Get",groups={"Test"})
      public void testFavouriteTemplateTestCase_Get(String casename,String token )throws Exception{
    	  String result = FavouriteTemplate.get(token);
    	  
    	  JSONArray jsonResult;
    	  if(result==null || result.isEmpty()){
    		  jsonResult = null;
    	  }else {
			jsonResult = new JSONArray(result);
		}
    	  
    	//设置检查点
    	 switch (casename) {
		case "Success":
			    assertEquals(jsonResult.getJSONObject(0).getString("FavorID").isEmpty(), false);
			break;
		default:
			break;
		}	  
      }
      
      /**
       * 帮忙医APP添加收藏模板FavouriteTemplate测试环境用例
       * @param token
       * @throws Exception
       */
      @Test(dataProvider="Test_Post",groups={"Test"})
      public void testFavouriteTemplateTestCase_Post(String casename,String tempId,String token)throws Exception{
    	  String result = FavouriteTemplate.post(tempId, token);
    	    
    	//设置检查点
    	  switch (casename) {
		case "AddTemplate":
			assertEquals(result,"1");
			break;
		default:
			break;
		}
      }
      
      /**
       * 帮忙医医生端删除收藏模板FavouriteTemplate测试环境测试用例
       * @param caseName
       * @param id
       * @param token
       * @throws Exception
       */
      @Test(dataProvider="Test_Del",groups="test")
      public void testFavouriteTemplate_Del(String caseName,String id,String token) throws Exception
      {
    	  if (caseName.equals("Success"))
    	  {
    		  FavouriteTemplate.post("163", token);
    		  String arry=FavouriteTemplate.get(token);
    		  JSONArray jsonArray=new JSONArray(arry);
    		  id=jsonArray.getJSONObject(0).getString("FavorID");
    	  }
    	  String result=FavouriteTemplate.delete(id, token);
    	  
    	  switch (caseName)
		{
			case "Success":
				Assert.assertEquals(result,"1");
				break;
			case "IdWrong":
				Assert.assertEquals(result,"0");
				break;
			case "IdNull":
				Assert.assertNull(result);
				break;
			case "TokenWrong":
				Assert.assertNull(result);
				break;
			case "TokenNull":
				Assert.assertNull(result);
				break;
			default:
				break;
		}
      }

      
}
